
<?php 
/* 
Template Name: prosessing_ngdung_notadmin-ajax
detail : remove người dung khong phai la admin set ra khoi bản user dăt lich
*/
?>
<?php
if ( !is_user_logged_in() ) 
    {
      ?>

        <div id='content_nano_two' class='clearfix' style='min-height:300px;'>
              <h1 style='color:#000;'>bạn không được phép truy cập trang này </h1>
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
        </div>
         
     <?php 
          
    }//if ( ! current_user_can( 'list_users' ) ) 
    elseif (is_user_logged_in() )  
 { 

    if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      {
       ?>

        <div id='content_nano_two' class='clearfix' style='min-height:300px;'>
              <h1 style='color:#000;'>bạn không được phép truy cập trang này </h1>
              <?php wp_die( __( 'Vui lòng đăng nhập hoặc quay lai trang chủ ! ' ) ); ?>
        </div>
         
     <?php 

      }//if ( ( $current_user->roles[0] == 'author') or ( $current_user->roles[0] == 'contributor') or ( $current_user->roles[0] == 'subscriber') ) 
      elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
      {
     
                        $id_may = $_POST['idmay'];
                        $ID = $_POST['idxoa'];
                       
                    $wpdb->delete( 'wp_user_wp_may', array( 'ID' => $ID ) );
     
        


      global $current_user;
      get_currentuserinfo();
      $id_user_now = $current_user->ID;



                            
                            $sql = "SELECT * FROM wp_user_wp_may
                                                        INNER JOIN wp_users
                                                                    ON wp_users.ID = wp_user_wp_may.ID
                                                                    WHERE id_may =".$id_may;  
                          
                             $row = $wpdb->get_results($sql);
                                                
                                                ?> 

                

                                               <table class="wp-list-table widefat fixed users" cellspacing="0">
                                                    <thead>
                                                     <tr>
                                                       <th scope="col" id="cb"  style=""> </th>
                                                       <th scope="col" id="username"  style=""> <span>Tài khoản</span></th>
                                                       <th scope="col" id="name"  style=""><span>Tên người dùng</span></th>
                                                       <th scope="col" id="email"style=""></th>
                                                     </tr>
                                                    </thead>
                                                     <tbody id="the-list" data-wp-lists="list:user">
                                        <?php 
     foreach($row as $key=>$value)
           {
                                          //var_dump($value);//break;
                if ( $id_user_now != $value->ID ) 
                 {
                  // truy van lay quyen quan tri
                             $id_user_meta_data = $wpdb->get_results("SELECT * FROM wp_usermeta WHERE user_id = ".$value->ID);

                               foreach ($id_user_meta_data as $key =>$vlue) 
                                   {
                                                                 
                                    if ( ($vlue ->meta_value == 'a:1:{s:11:"contributor";b:1;}' ) or ($vlue ->meta_value == 'a:1:{s:6:"editor";b:1;}' )   ) 
                                       {

                                         ?>
                                              <tr id="user-<?php echo $value->ID; ?>" class="alternate">
                                                   <th scope="row" class="check-column">
                                                     <label class="screen-reader-text" for="cb-select-1"></label>
                                                   </th>
                                                     <td class="username column-username">
                                                       <strong><?php echo $value->user_login;?></strong>
                                                    </td>
                                                    <td class="name column-name"><?php echo $value->display_name;?></td>
                                                    <td class="email column-email">
                                                       
                                                       <ul style='position: relative;'>
                                                        <li style='height: 30px;'>
                                                        <input type="button" 
                                                         nguoidung="<?php echo $value->ID; ?>" 
                                                         idmay="<?php echo $id_may;?>"
                                                         name="delng<?php echo $value->ID; ?>" 
                                                         id="delnguoidung" 
                                                         class="delnguoidung"
                                                         value="Xóa"
                                                      
                                                         />
                                                       </li></ul>
                                                         <!-- onclick="return confirm('Bạn không xóa máy này ?')"; -->
                                                    </td>
                                                                                         
                                                      </tr><!-- id="user-xyz" class="alternate" -->
                                        <?php             
              }//  if ($vlue ->meta_value == 'a:1:{s:11:"contributor";b:1;}') 
          }//  foreach ($id_user_meta_data as $key =>$vlue) 
    }//  if ( $id_user_now != $value->ID )                      

  }// foreach($row as $key=>$value)
                                          ?>

                                               </tbody>
                                                      </table>    
                      

                 <script type="text/javascript">

                     function load_set_user_ng(idmay) 
                                  {
                                    
                                    var idmay = idmay;
                                   
                                      $.ajax({
                                              url:"<?php bloginfo('url');?>/load_prosessing_ngdung_notadmin",
                                              type:"POST",
                                              data: {idmay:idmay},
                                              dataType:"JSON",
                                              success: function(data_user_nd)
                                              {
                                                //alert(data_user_nd);
                                               // debugger;
                                               // return;
                                               var xoangdung = [];
                                               $.each(data_user_nd, function(key,value)
                                                {
                                                  xoangdung.push('<li>' +  'ID: ' + value.ID + 'id_may : ' + value.id_may + 'user_login : ' + value.user_login + '<li>');
                                               });
                                               $('<ul/>',{html:xoangdung.join('')}).appendTo('#content_add_nguoi_editor');
                                               $('.content-2 .wp-list-table.widefat.fixed.users').css('display','none');
                                               $('.content-2').css({ position: 'absolute', left: '9000000'});
                                               $('.content-1 .wp-list-table.widefat.fixed.users').css('display','none');
                                               $('#content_addqli').css('width', '960');
                                               $('#content_addqli').css('position', 'relative');
                                               $('#content_addqli').css('z-index', '2003');
                                               $('.content-1 .wp-list-table.widefat.fixed.users').css('z-index', '2001');
                                               $('.content-2').css('min-height', '0');
                                               $('.content div').css({
                                                  position: 'relative',
                                                  overflow: 'none'
                                                });

                                               }
                                        });
                             
                                  }

                       
                               jQuery(document).ready(function(){

                                    $("td input[name^='delng']").click(function() {
                                    var idxoa = $(this).attr("nguoidung");
                                    var idmay = $(this).attr("idmay");
                                    //alert(nguoidung);
                                    //alert(idmay);
                                    //return;
                                    $.ajax({
                                            url:"<?php bloginfo('url');?>/prosessing_ngdung_notadmin",
                                              type:"POST",
                                              data: {idxoa:idxoa,idmay:idmay},
                                              success: function(data)
                                              {
                                               // alert(data);
                                                //load_set_user_ng(idmay);
                                                 $('#phanquyenguoidungbinhthuong').html(data);
                                              }
                                        });
                                    });
                                      
                                  })
                             
                 </script>


                  <script type="text/javascript">
                  /***************************/
                  //@Author: PHUC IT
                  //@website: www.maybanhang.net
                  //@email: phuca4@gmail.com
                  /***************************/
                           var popupStatus = 0;

                            function loadPopup(){
                              if(popupStatus==0){
                                $("#backgroundPopup").css({
                                  "opacity": "0.7"
                                });
                                $("#backgroundPopup").fadeIn("slow");
                                $("#dialog-form-them-nguoi-dung").fadeIn("slow");
                                popupStatus = 1;
                              }
                            }

                            function disablePopup(){
                              if(popupStatus==1){
                                $("#backgroundPopup").fadeOut("slow");
                                $("#dialog-form-them-nguoi-dung").fadeOut("slow");
                                 // bo check input 
                                $('#dialog-form-them-nguoi-dung').find(':checked').each(function() 
                                      {
                                       $(this).removeAttr('checked');
                                    });
                                popupStatus = 0;
                              }
                            }

                            //centering popup
                            function centerPopup(){
                              //request data for centering
                              var windowWidth = document.documentElement.clientWidth;
                              var windowHeight = document.documentElement.clientHeight;
                              var popupHeight = $("#dialog-form-them-nguoi-dung").height();
                              var popupWidth = $("#dialog-form-them-nguoi-dung").width();
                              

                              $("#dialog-form-them-nguoi-dung").css({
                                "position": "absolute",
                                "top": windowHeight/2-popupHeight/2,
                                "left": windowWidth/2-popupWidth/2,
                              });
                              
                              $("#backgroundPopup").css({
                                "height": windowHeight
                              });
                            }

                            // jQuery(document).ready(function()
               jQuery(document).ready(function(){
                              
                              $("#adduserngdung").click(function(){
                                //centering with css
                                centerPopup();
                                //load popup
                                loadPopup();
                              });
                                    
                              //CLOSING POPUP
                              //Click the x event!
                              jQuery("#popupCloseng").click(function(){
                                disablePopup();
                              });
                              //Click out event!
                              $("#backgroundPopup").click(function(){
                                disablePopup();
                              });
                              //Press Escape event!
                              $(document).keypress(function(e){
                                if(e.keyCode==27 && popupStatus==1){
                                  disablePopup();
                                }
                              });

                            });
                            
                </script>
                </p>



              <?php 
                    echo '<h1></h1>';
                    echo '<h1> Xóa người dùng thành công </h1>';
                    return;
 
                        
 } //  elseif ( ( $current_user->roles[0] != 'author') or ( $current_user->roles[0] != 'contributor') or ( $current_user->roles[0] != 'subscriber') )
} //elseif ( ! current_user_can( 'list_users' ) ) ?>
